package com.littleken.core.validate;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.awt.image.BufferedImage;
import java.time.LocalDateTime;

/**
 * 图形验证码实体类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ImageCode {

    //图片
    private BufferedImage image;
    //验证码
    private String code;
    //过期时间
    private LocalDateTime expireTime;

    //判断是否已经过期
    public boolean isExpried(){
        return LocalDateTime.now().isAfter(expireTime);
    }

    /**
     *
     * @param image
     * @param code
     * @param expireIn 过期秒数
     */
    public ImageCode(BufferedImage image, String code, int expireIn) {
        this.image = image;
        this.code = code;
        this.expireTime = LocalDateTime.now().plusSeconds(expireIn);
    }

}
